import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/page/home/subs/person_detail/controller.dart';
import 'package:search_people/utils/component/page_state/widgets/widgets.dart';
import 'package:search_people/utils/fun_util.dart';
import 'package:search_people/value/topcolors.dart';

import '../models/person_history_model.dart';

class PersonHistoryWidget extends StatelessWidget {
  const PersonHistoryWidget({Key? key, required this.controller})
      : super(key: key);
  final PersonDetailController controller;
  Widget _buildItemView(PersonHistoryModel mod) {
    return Stack(
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(
              width: 12.r,
            ),
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  alignment: Alignment.centerLeft,
                  height: 30.r,
                  width: 70.r,
                  child: Text(
                    mod.beginTimeStr ?? '',
                    style: TextStyle(
                      color: TopColors.black_33,
                      fontSize: 12.sp,
                    ),
                  ),
                ),
                SizedBox(
                  width: 5.r,
                ),
                Container(
                  width: 30.r,
                  height: 30.r,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      border: Border.all(color: TopColors.main_color, width: 1),
                      borderRadius: BorderRadius.circular(15.r)),
                  child: Text(
                    mod.age ?? '',
                    style: TextStyle(
                      color: TopColors.main_color,
                      fontSize: 10.r,
                    ),
                  ),
                ),
              ],
            ),
            SizedBox(
              width: 10.r,
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 20.r),
                    padding:
                        EdgeInsets.symmetric(horizontal: 5.r, vertical: 3.r),
                    decoration: BoxDecoration(
                        color: const Color(0xffE4F1FE),
                        border: Border.all(color: TopColors.main_color),
                        borderRadius: BorderRadius.circular(2)),
                    child: Text(
                      mod.workingHours ?? '',
                      style: TextStyle(
                        color: TopColors.main_color,
                        fontSize: 11.r,
                      ),
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 15.r),
                    constraints: BoxConstraints(maxHeight: 200.r),
                    child: Text(
                      mod.jobContent ?? '',
                      style: TextStyle(
                        color: TopColors.black_33,
                        fontSize: 12.sp,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(
              width: 12.r,
            ),
          ],
        ),
        Positioned(
            left: 95.r,
            bottom: 0,
            top: 30.r,
            child: VerticalDivider(
              color: Colors.grey[400],
            )),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(children: [
        Container(
          height: 8.r,
          color: TopColors.bg,
        ),
        Container(
          height: 45.r,
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.only(left: 12.r),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Container(
                    height: 15.r,
                    width: 5.r,
                    margin: EdgeInsets.only(right: 10.r),
                    color: TopColors.main_color,
                  ),
                  Text(
                    '人物履历',
                    style: TextStyle(
                      color: TopColors.black_33,
                      fontSize: 14.sp,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
              IconButton(
                  onPressed: () {
                    controller.state.isShowHistory =
                        !controller.state.isShowHistory;
                    controller.update();
                  },
                  icon: Icon(
                    controller.state.isShowHistory
                        ? Icons.keyboard_arrow_down_outlined
                        : Icons.keyboard_arrow_right_outlined,
                    color: TopColors.main_color,
                  ))
            ],
          ),
        ),
        !controller.state.isShowHistory
            ? const SizedBox()
            : isZeroList(controller.state.historyMds)
                ? EmptyView()
                : Column(
                    children: (controller.state.historyMds ?? [])
                        .map((e) => _buildItemView(e))
                        .toList(),
                  )
      ]),
    );
  }
}
